package p270jp.pxv.android.activity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.app.AlertController;
import androidx.appcompat.app.AlertDialog;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.BackStackRecord;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import com.google.android.gms.actions.SearchIntents;
import com.google.android.material.tabs.TabLayout;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import p014ae.AbstractActivityC0167u3;
import p014ae.C0162t8;
import p014ae.DialogInterface$OnClickListenerC0150r8;
import p014ae.DialogInterface$OnClickListenerC0191y5;
import p045be.SearchResultPagerAdapter;
import p047bg.C1124a;
import p060c2.Chain;
import p079cl.SearchResultPresenter;
import p090d0.C2518n;
import p134ei.AnalyticsAction;
import p134ei.PixivAnalytics;
import p165fo.Subscribe;
import p184gi.ABTestingEvent;
import p189gn.AbstractC3446l;
import p209hg.AbstractC3608h;
import p209hg.SearchResultContract;
import p210hh.PixivAccountManager;
import p270jp.pxv.android.R;
import p270jp.pxv.android.activity.SearchResultActivity;
import p270jp.pxv.android.event.SearchAutoCompleteEvent;
import p270jp.pxv.android.event.SearchHistoryEvent;
import p270jp.pxv.android.event.ShowRequiredPremiumDialogEvent;
import p270jp.pxv.android.legacy.constant.ContentType;
import p270jp.pxv.android.legacy.constant.SearchSort;
import p270jp.pxv.android.legacy.constant.SearchTarget;
import p270jp.pxv.android.model.SearchBookmarkRange;
import p270jp.pxv.android.model.SearchDurationParameter;
import p270jp.pxv.android.model.SearchHistoryDaoManager;
import p270jp.pxv.android.model.SearchParameter;
import p307l9.EdgeTreatment;
import p314lg.ActivitySearchResultBinding;
import p325m0.MutabilityOwnership;
import p344mj.SearchQueryEditorActionListener;
import p347mm.SearchAnalyticsUtils;
import p452qn.C5859m;
import p452qn.StringsJVM;
import p547uh.SearchAutocompleteFragment;
import p547uh.SearchHistoryFragment;
import p547uh.SearchResultPremiumPreviewIllustFragment;
import p547uh.SearchResultPremiumPreviewNovelFragment;
import p547uh.SearchResultPremiumTrialIllustFragment;
import p547uh.SearchUserResultFragment;
import p639y6.C7296l;
import p651yi.PremiumTrialService;

/* renamed from: jp.pxv.android.activity.SearchResultActivity */
/* loaded from: classes2.dex */
public class SearchResultActivity extends AbstractActivityC0167u3 implements AbstractC3608h, SearchQueryEditorActionListener {

    /* renamed from: h0 */
    public static final /* synthetic */ int f18665h0;

    /* renamed from: b0 */
    public SearchResultContract f18666b0;

    /* renamed from: c0 */
    public boolean f18667c0;

    /* renamed from: d0 */
    public SearchResultPagerAdapter f18668d0;

    /* renamed from: e0 */
    public PremiumTrialService f18669e0;

    /* renamed from: f0 */
    public SearchHistoryDaoManager f18670f0;

    /* renamed from: g0 */
    public ActivitySearchResultBinding f18671g0;

    /* renamed from: jp.pxv.android.activity.SearchResultActivity$a */
    /* loaded from: classes2.dex */
    public class C4115a extends ViewPager.C0900k {
        public C4115a() {
            SearchResultActivity.this = r1;
        }

        @Override // androidx.viewpager.widget.ViewPager.AbstractC0898i
        /* renamed from: Y */
        public void mo943Y(int i) {
            SearchResultActivity searchResultActivity = SearchResultActivity.this;
            SearchResultPagerAdapter b2Var = searchResultActivity.f18668d0;
            ViewPager viewPager = searchResultActivity.f18671g0.f22094B;
            Objects.requireNonNull(b2Var);
            Fragment fragment = (Fragment) b2Var.mo936f(viewPager, viewPager.getCurrentItem());
            if (fragment instanceof SearchResultPremiumTrialIllustFragment) {
                SearchResultPremiumTrialIllustFragment q9Var = (SearchResultPremiumTrialIllustFragment) fragment;
                PixivAnalytics.m6529a((PixivAnalytics) q9Var.f27901C.getValue(), 7, AnalyticsAction.PREMIUM_POPULAR_PREVIEW_VIEW_AT_SEARCH_RESULT_POPULAR, null, 4);
                RecyclerView recyclerView = q9Var.f27635c;
                if (recyclerView != null) {
                    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                    Objects.requireNonNull(layoutManager, "null cannot be cast to non-null type androidx.recyclerview.widget.LinearLayoutManager");
                    int g1 = ((LinearLayoutManager) layoutManager).m10935g1();
                    RecyclerView.LayoutManager layoutManager2 = q9Var.f27635c.getLayoutManager();
                    Objects.requireNonNull(layoutManager2, "null cannot be cast to non-null type androidx.recyclerview.widget.LinearLayoutManager");
                    int h1 = ((LinearLayoutManager) layoutManager2).m10934h1();
                    HashMap hashMap = new HashMap();
                    hashMap.put(31, AnalyticsAction.PREMIUM_ABOUT_PREMIUM_BUTTON_VIEW_AT_SEARCH_RESULT_POPULAR_BOTTOM);
                    C1124a.m10198P(-1, -1, g1, h1, hashMap);
                }
            } else if (fragment instanceof SearchResultPremiumPreviewIllustFragment) {
                SearchResultPremiumPreviewIllustFragment l9Var = (SearchResultPremiumPreviewIllustFragment) fragment;
                l9Var.f27751C.getValue().m6528b(7, AnalyticsAction.PREMIUM_POPULAR_PREVIEW_VIEW_AT_SEARCH_RESULT_POPULAR);
                RecyclerView recyclerView2 = l9Var.f27635c;
                if (recyclerView2 != null) {
                    C1124a.m10198P(-1, -1, ((LinearLayoutManager) recyclerView2.getLayoutManager()).m10935g1(), ((LinearLayoutManager) l9Var.f27635c.getLayoutManager()).m10934h1(), SearchResultPremiumPreviewIllustFragment.m1562w());
                }
            } else if (fragment instanceof SearchResultPremiumPreviewNovelFragment) {
                SearchResultPremiumPreviewNovelFragment n9Var = (SearchResultPremiumPreviewNovelFragment) fragment;
                n9Var.f27814B.getValue().m6528b(7, AnalyticsAction.PREMIUM_POPULAR_PREVIEW_VIEW_AT_SEARCH_RESULT_POPULAR);
                RecyclerView recyclerView3 = n9Var.f27635c;
                if (recyclerView3 != null) {
                    C1124a.m10198P(-1, -1, ((LinearLayoutManager) recyclerView3.getLayoutManager()).m10935g1(), ((LinearLayoutManager) n9Var.f27635c.getLayoutManager()).m10934h1(), SearchResultPremiumPreviewNovelFragment.m1540w());
                }
            }
            SearchResultPresenter kVar = (SearchResultPresenter) SearchResultActivity.this.f18666b0;
            kVar.m9713m(kVar.m9717i().get(i));
        }
    }

    /* renamed from: jp.pxv.android.activity.SearchResultActivity$b */
    /* loaded from: classes2.dex */
    public class C4116b implements TabLayout.AbstractC2202d {
        public C4116b() {
            SearchResultActivity.this = r1;
        }

        @Override // com.google.android.material.tabs.TabLayout.AbstractC2201c
        /* renamed from: a */
        public void mo4699a(TabLayout.C2207g gVar) {
            String str;
            SearchResultPresenter kVar = (SearchResultPresenter) SearchResultActivity.this.f18666b0;
            if (kVar.f5578h.contains(kVar.m9717i().get(gVar.f9764d)) && PixivAccountManager.m5511e().f16503i) {
                AbstractC3608h hVar = kVar.f5572b;
                MutabilityOwnership.m3747j(hVar);
                List<SearchSort> list = kVar.f5578h;
                SearchResultActivity searchResultActivity = (SearchResultActivity) hVar;
                String[] strArr = new String[list.size()];
                for (int i = 0; i < list.size(); i++) {
                    int i2 = C4117c.f18674a[list.get(i).ordinal()];
                    if (i2 == 1) {
                        str = searchResultActivity.getString(R.string.search_order_popular);
                    } else if (i2 == 2) {
                        str = searchResultActivity.getString(R.string.search_order_popular_dialog_male);
                    } else if (i2 != 3) {
                        str = null;
                    } else {
                        str = searchResultActivity.getString(R.string.search_order_popular_dialog_female);
                    }
                    strArr[i] = str;
                }
                AlertDialog.C0305a aVar = new AlertDialog.C0305a(searchResultActivity);
                DialogInterface$OnClickListenerC0150r8 r8Var = new DialogInterface$OnClickListenerC0150r8(searchResultActivity, 0);
                AlertController.C0299b bVar = aVar.f1085a;
                bVar.f1066p = strArr;
                bVar.f1068r = r8Var;
                aVar.m12005i();
            }
        }

        @Override // com.google.android.material.tabs.TabLayout.AbstractC2201c
        /* renamed from: b */
        public void mo4698b(TabLayout.C2207g gVar) {
        }

        @Override // com.google.android.material.tabs.TabLayout.AbstractC2201c
        /* renamed from: c */
        public void mo4697c(TabLayout.C2207g gVar) {
        }
    }

    /* renamed from: jp.pxv.android.activity.SearchResultActivity$c */
    /* loaded from: classes2.dex */
    public static /* synthetic */ class C4117c {

        /* renamed from: a */
        public static final /* synthetic */ int[] f18674a;

        static {
            int[] iArr = new int[SearchSort.values().length];
            f18674a = iArr;
            try {
                iArr[SearchSort.POPULAR_DESC.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f18674a[SearchSort.POPULAR_MALE_DESC.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f18674a[SearchSort.POPULAR_FEMALE_DESC.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    /* renamed from: e1 */
    public static Intent m4710e1(Context context, ContentType contentType, String str, SearchTarget searchTarget) {
        EdgeTreatment.m3909i(context);
        EdgeTreatment.m3909i(contentType);
        EdgeTreatment.m3909i(str);
        EdgeTreatment.m3909i(searchTarget);
        Intent intent = new Intent(context, SearchResultActivity.class);
        intent.putExtra("CONTENT_TYPE", (Parcelable) contentType);
        intent.putExtra("QUERY", str);
        intent.putExtra("SEARCH_TARGET", searchTarget);
        return intent;
    }

    /* renamed from: f1 */
    public void m4709f1(String str) {
        SearchResultPresenter kVar = (SearchResultPresenter) this.f18666b0;
        Objects.requireNonNull(kVar);
        MutabilityOwnership.m3745m(str, "searchQuery");
        PixivAnalytics eVar = kVar.f5573c;
        AnalyticsAction a = SearchAnalyticsUtils.m3538a(kVar.f5582l, 1);
        MutabilityOwnership.m3746l(a, "getAnalyticsAction(conte…ticsUtils.Location.INPUT)");
        eVar.m6527c(4, a, str);
        kVar.m9714l(kVar.f5582l, str);
    }

    /* renamed from: g1 */
    public void m4708g1() {
        this.f18671g0.f22096r.setVisibility(8);
        SearchAutocompleteFragment s8Var = (SearchAutocompleteFragment) m11131K0().m11280E(R.id.auto_complete_fragment_container);
        if (s8Var != null) {
            BackStackRecord cVar = new BackStackRecord(m11131K0());
            cVar.mo11166i(s8Var);
            cVar.mo11170e();
        }
    }

    /* renamed from: h1 */
    public void m4707h1() {
        this.f18671g0.f22100v.setVisibility(8);
    }

    /* renamed from: i1 */
    public void m4706i1() {
        Fragment E = m11131K0().m11280E(R.id.search_user_result_fragment_container);
        if (E != null) {
            BackStackRecord cVar = new BackStackRecord(m11131K0());
            cVar.mo11166i(E);
            cVar.mo11171d();
        }
        this.f18671g0.f22102x.setVisibility(8);
    }

    /* renamed from: j1 */
    public void m4705j1() {
        this.f18671g0.f22094B.setVisibility(8);
        this.f18671g0.f22104z.setVisibility(8);
    }

    /* renamed from: k1 */
    public void m4704k1(String str) {
        SearchResultPresenter kVar = (SearchResultPresenter) this.f18666b0;
        Objects.requireNonNull(kVar);
        MutabilityOwnership.m3745m(str, SearchIntents.EXTRA_QUERY);
        kVar.f5575e = true;
        kVar.f5580j = str;
        AbstractC3608h hVar = kVar.f5572b;
        MutabilityOwnership.m3747j(hVar);
        ((SearchResultActivity) hVar).m4702m1(false);
        AbstractC3608h hVar2 = kVar.f5572b;
        MutabilityOwnership.m3747j(hVar2);
        ((SearchResultActivity) hVar2).m4703l1(0);
        AbstractC3608h hVar3 = kVar.f5572b;
        MutabilityOwnership.m3747j(hVar3);
        ((SearchResultActivity) hVar3).m4705j1();
        AbstractC3608h hVar4 = kVar.f5572b;
        MutabilityOwnership.m3747j(hVar4);
        ((SearchResultActivity) hVar4).m4706i1();
        AbstractC3608h hVar5 = kVar.f5572b;
        MutabilityOwnership.m3747j(hVar5);
        ((SearchResultActivity) hVar5).m4708g1();
        kVar.f5576f.m11032n(kVar.f5582l);
    }

    /* renamed from: l1 */
    public void m4703l1(int i) {
        this.f18671g0.f22103y.setVisibility(i);
    }

    /* renamed from: m1 */
    public void m4702m1(boolean z) {
        this.f18667c0 = z;
        m7045O0().mo7001l();
    }

    /* renamed from: n1 */
    public void m4701n1(String str) {
        this.f18671g0.f22102x.setVisibility(0);
        this.f18671g0.f22101w.setSearchQuery(str);
        this.f18671g0.f22101w.clearFocus();
        C1124a.m10170v(this.f18671g0.f22101w);
        SearchUserResultFragment s9Var = new SearchUserResultFragment();
        Bundle bundle = new Bundle();
        bundle.putString("QUERY", str);
        s9Var.setArguments(bundle);
        BackStackRecord cVar = new BackStackRecord(m11131K0());
        cVar.m11165j(R.id.search_user_result_fragment_container, s9Var);
        cVar.mo11171d();
    }

    /* renamed from: o1 */
    public void m4700o1(SearchParameter searchParameter, List<SearchSort> list, boolean z) {
        this.f18671g0.f22101w.setSearchQuery(searchParameter.getQuery());
        this.f18671g0.f22101w.clearFocus();
        C1124a.m10170v(this.f18671g0.f22101w);
        this.f18671g0.f22104z.setVisibility(0);
        int indexOf = list.indexOf(searchParameter.getSort());
        if (z) {
            if (this.f18668d0 != null) {
                for (int i = 0; i < this.f18668d0.mo938c(); i++) {
                    this.f18668d0.mo939a(null, i, (Fragment) this.f18668d0.mo936f(this.f18671g0.f22094B, i));
                }
            }
            SearchResultPagerAdapter b2Var = new SearchResultPagerAdapter(this, m11131K0(), this.f18669e0, searchParameter, list);
            this.f18668d0 = b2Var;
            this.f18671g0.f22094B.setAdapter(b2Var);
        }
        ActivitySearchResultBinding p1Var = this.f18671g0;
        p1Var.f22104z.setupWithViewPager(p1Var.f22094B);
        this.f18671g0.f22094B.setCurrentItem(indexOf);
        this.f18671g0.f22094B.setVisibility(0);
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, android.app.Activity
    public void onActivityResult(int i, int i2, Intent intent) {
        Serializable serializable;
        Serializable serializable2;
        super.onActivityResult(i, i2, intent);
        SearchResultPresenter kVar = (SearchResultPresenter) this.f18666b0;
        Objects.requireNonNull(kVar);
        if (i2 == -1 && i == 107) {
            Serializable serializable3 = null;
            if (intent == null) {
                serializable = null;
            } else {
                serializable = intent.getSerializableExtra("RESULT_BUNDLE_KEY_FILTER_TARGET");
            }
            kVar.f5583m = (SearchTarget) serializable;
            if (intent == null) {
                serializable2 = null;
            } else {
                serializable2 = intent.getSerializableExtra("RESULT_BUNDLE_KEY_FILTER_DURATION");
            }
            kVar.f5586p = (SearchDurationParameter) serializable2;
            if (intent != null) {
                serializable3 = intent.getSerializableExtra("RESULT_BUNDLE_KEY_FILTER_BOOKMARK_RANGE");
            }
            kVar.f5585o = (SearchBookmarkRange) serializable3;
            kVar.m9714l(kVar.f5582l, kVar.f5580j);
        }
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, androidx.activity.ComponentActivity, android.app.Activity
    public void onBackPressed() {
        SearchResultPresenter kVar = (SearchResultPresenter) this.f18666b0;
        boolean z = false;
        if (kVar.f5575e) {
            SearchParameter.Builder durationParameter = new SearchParameter.Builder(kVar.f5582l, kVar.f5581k).setTarget(kVar.f5583m).setSort(kVar.f5584n).setDurationParameter(kVar.f5586p);
            SearchBookmarkRange searchBookmarkRange = kVar.f5585o;
            MutabilityOwnership.m3747j(searchBookmarkRange);
            SearchParameter build = durationParameter.setBookmarkRange(searchBookmarkRange).build();
            AbstractC3608h hVar = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar);
            ((SearchResultActivity) hVar).m4703l1(8);
            AbstractC3608h hVar2 = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar2);
            ((SearchResultActivity) hVar2).m4708g1();
            AbstractC3608h hVar3 = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar3);
            ((SearchResultActivity) hVar3).m4707h1();
            if (kVar.f5582l == ContentType.USER) {
                AbstractC3608h hVar4 = kVar.f5572b;
                MutabilityOwnership.m3747j(hVar4);
                ((SearchResultActivity) hVar4).m4705j1();
                AbstractC3608h hVar5 = kVar.f5572b;
                MutabilityOwnership.m3747j(hVar5);
                ((SearchResultActivity) hVar5).m4701n1(kVar.f5581k);
                AbstractC3608h hVar6 = kVar.f5572b;
                MutabilityOwnership.m3747j(hVar6);
                ((SearchResultActivity) hVar6).m4702m1(false);
            } else {
                AbstractC3608h hVar7 = kVar.f5572b;
                MutabilityOwnership.m3747j(hVar7);
                ((SearchResultActivity) hVar7).m4706i1();
                AbstractC3608h hVar8 = kVar.f5572b;
                MutabilityOwnership.m3747j(hVar8);
                ((SearchResultActivity) hVar8).m4700o1(build, kVar.m9717i(), false);
                AbstractC3608h hVar9 = kVar.f5572b;
                MutabilityOwnership.m3747j(hVar9);
                ((SearchResultActivity) hVar9).m4702m1(true);
            }
            kVar.f5575e = false;
            z = true;
        }
        if (!z) {
            super.onBackPressed();
        }
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        int i;
        super.onCreate(bundle);
        ActivitySearchResultBinding p1Var = (ActivitySearchResultBinding) DataBindingUtil.m11369d(this, R.layout.activity_search_result);
        this.f18671g0 = p1Var;
        C1124a.m10196R(this, p1Var.f22093A, "");
        this.f18669e0 = (PremiumTrialService) C2518n.m7641d(PremiumTrialService.class);
        this.f18670f0 = (SearchHistoryDaoManager) C2518n.m7641d(SearchHistoryDaoManager.class);
        this.f18671g0.f22094B.m10517b(new C4115a());
        TabLayout tabLayout = this.f18671g0.f22104z;
        C4116b bVar = new C4116b();
        if (!tabLayout.f9711H.contains(bVar)) {
            tabLayout.f9711H.add(bVar);
        }
        this.f18671g0.f22103y.setOnSelectSegmentListener(new C7296l(this, 9));
        this.f18671g0.f22101w.setSearchQueryEditorActionListener(this);
        SearchResultPresenter kVar = new SearchResultPresenter(this, this, this.f18757A, this.f18670f0);
        this.f18666b0 = kVar;
        Intent intent = getIntent();
        MutabilityOwnership.m3745m(intent, "intent");
        boolean z = false;
        if (bundle == null) {
            kVar.f5582l = (ContentType) intent.getParcelableExtra("CONTENT_TYPE");
            kVar.f5580j = intent.getStringExtra("QUERY");
            kVar.f5583m = (SearchTarget) intent.getSerializableExtra("SEARCH_TARGET");
            kVar.m9713m(kVar.m9717i().get(0));
        } else {
            kVar.f5582l = (ContentType) bundle.getParcelable("CONTENT_TYPE");
            kVar.f5580j = bundle.getString("QUERY");
            kVar.f5581k = bundle.getString("LAST_SEARCH_QUERY");
            kVar.f5583m = (SearchTarget) bundle.getSerializable("SEARCH_TARGET");
            kVar.f5584n = (SearchSort) bundle.getSerializable("SEARCH_SORT");
            Serializable serializable = bundle.getSerializable("SORT_MENU_POPULARITY");
            if (serializable != null) {
                kVar.f5579i = (SearchSort) serializable;
            }
            kVar.f5585o = (SearchBookmarkRange) bundle.getSerializable("SEARCH_BOOKMARK_RANGE");
            kVar.f5586p = (SearchDurationParameter) bundle.getSerializable("SEARCH_DURATION");
        }
        ContentType contentType = kVar.f5582l;
        String[] stringArray = kVar.f5571a.getResources().getStringArray(R.array.illustmanga_novel_user);
        MutabilityOwnership.m3746l(stringArray, "context.resources.getStr…y.illustmanga_novel_user)");
        if (contentType == null) {
            i = -1;
        } else {
            i = SearchResultPresenter.C1191a.f5587a[contentType.ordinal()];
        }
        if (i == 1 || i == 2) {
            AbstractC3608h hVar = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar);
            ((SearchResultActivity) hVar).f18671g0.f22103y.m4467a(stringArray, 0);
        } else if (i == 3) {
            AbstractC3608h hVar2 = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar2);
            ((SearchResultActivity) hVar2).f18671g0.f22103y.m4467a(stringArray, 1);
        } else if (i == 4) {
            AbstractC3608h hVar3 = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar3);
            ((SearchResultActivity) hVar3).f18671g0.f22103y.m4467a(stringArray, 2);
        }
        String str = kVar.f5580j;
        MutabilityOwnership.m3747j(str);
        String w = StringsJVM.m2749w(str, "\u3000", " ", false, 4);
        int length = w.length() - 1;
        int i2 = 0;
        boolean z2 = false;
        while (i2 <= length) {
            boolean z3 = MutabilityOwnership.m3743o(w.charAt(!z2 ? i2 : length), 32) <= 0;
            if (!z2) {
                if (!z3) {
                    z2 = true;
                } else {
                    i2++;
                }
            } else if (!z3) {
                break;
            } else {
                length--;
            }
        }
        String obj = w.subSequence(i2, length + 1).toString();
        kVar.f5580j = obj;
        if (MutabilityOwnership.m3749h(obj, "")) {
            AbstractC3608h hVar4 = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar4);
            ((SearchResultActivity) hVar4).m4702m1(false);
            AbstractC3608h hVar5 = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar5);
            ((SearchResultActivity) hVar5).m4703l1(0);
            AbstractC3608h hVar6 = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar6);
            ((SearchResultActivity) hVar6).m4705j1();
            AbstractC3608h hVar7 = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar7);
            ((SearchResultActivity) hVar7).m4706i1();
            AbstractC3608h hVar8 = kVar.f5572b;
            MutabilityOwnership.m3747j(hVar8);
            ((SearchResultActivity) hVar8).m4708g1();
            kVar.f5576f.m11032n(kVar.f5582l);
        } else {
            kVar.m9714l(kVar.f5582l, kVar.f5580j);
        }
        ((SearchResultPresenter) this.f18666b0).f5576f.mo2790a(this, new AbstractC3446l() { // from class: ae.u8
            @Override // p189gn.AbstractC3446l
            public final Object invoke(Object obj2) {
                SearchResultActivity searchResultActivity = SearchResultActivity.this;
                ContentType contentType2 = (ContentType) obj2;
                searchResultActivity.f18671g0.f22100v.setVisibility(0);
                Objects.requireNonNull(SearchHistoryFragment.f28253j);
                MutabilityOwnership.m3745m(contentType2, "contentType");
                SearchHistoryFragment z8Var = new SearchHistoryFragment();
                Bundle bundle2 = new Bundle();
                bundle2.putParcelable("CONTENT_TYPE", contentType2);
                z8Var.setArguments(bundle2);
                BackStackRecord cVar = new BackStackRecord(searchResultActivity.m11131K0());
                cVar.m11165j(R.id.history_fragment_container, z8Var);
                cVar.mo11171d();
                return null;
            }
        });
        ((SearchResultPresenter) this.f18666b0).f5577g.mo2790a(this, new C0162t8(this, 0));
        if (getIntent().getBooleanExtra("OPEN_SEARCH_FILTER", false) && bundle == null) {
            z = true;
        }
        if (z) {
            ((SearchResultPresenter) this.f18666b0).m9716j();
        }
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.search_result, menu);
        return true;
    }

    @Override // p014ae.AdActivity, p270jp.pxv.android.activity.BaseActivity, p116e.ActivityC2727f, androidx.fragment.app.FragmentActivity, android.app.Activity
    public void onDestroy() {
        List<ViewPager.AbstractC0898i> list = this.f18671g0.f22094B.f4038R;
        if (list != null) {
            list.clear();
        }
        super.onDestroy();
        ((SearchResultPresenter) this.f18666b0).f5572b = null;
    }

    @Subscribe
    public void onEvent(SearchAutoCompleteEvent searchAutoCompleteEvent) {
        SearchResultContract gVar = this.f18666b0;
        String searchQuery = this.f18671g0.f22101w.getSearchQuery();
        String searchWord = searchAutoCompleteEvent.getSearchWord();
        SearchResultPresenter kVar = (SearchResultPresenter) gVar;
        Objects.requireNonNull(kVar);
        MutabilityOwnership.m3745m(searchQuery, "currentInputedSearchQuery");
        MutabilityOwnership.m3745m(searchWord, "autoCompletedSearchWord");
        kVar.f5573c.m6526d(ABTestingEvent.C3331c.f15549a);
        kVar.f5573c.m6526d(ABTestingEvent.C3329a.f15547a);
        Object[] array = C5859m.m2727T(searchQuery, new String[]{" "}, false, 0, 6).toArray(new String[0]);
        Objects.requireNonNull(array, "null cannot be cast to non-null type kotlin.Array<T>");
        String[] strArr = (String[]) array;
        List B = Chain.m9958B(Arrays.copyOf(strArr, strArr.length));
        if (B.size() <= 1) {
            kVar.m9714l(kVar.f5582l, searchWord);
            return;
        }
        B.remove(B.size() - 1);
        kVar.m9714l(kVar.f5582l, TextUtils.join(" ", B) + ' ' + searchWord);
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, androidx.activity.ComponentActivity, android.app.Activity
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != R.id.menu_search_filter) {
            return super.onOptionsItemSelected(menuItem);
        }
        ((SearchResultPresenter) this.f18666b0).m9716j();
        return true;
    }

    @Override // android.app.Activity
    public boolean onPrepareOptionsMenu(Menu menu) {
        menu.findItem(R.id.menu_search_filter).setVisible(this.f18667c0);
        return super.onPrepareOptionsMenu(menu);
    }

    @Override // androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        SearchResultPresenter kVar = (SearchResultPresenter) this.f18666b0;
        Objects.requireNonNull(kVar);
        MutabilityOwnership.m3745m(bundle, "outState");
        bundle.putParcelable("CONTENT_TYPE", kVar.f5582l);
        bundle.putString("QUERY", kVar.f5580j);
        bundle.putString("LAST_SEARCH_QUERY", kVar.f5581k);
        bundle.putSerializable("SEARCH_TARGET", kVar.f5583m);
        bundle.putSerializable("SEARCH_SORT", kVar.f5584n);
        bundle.putSerializable("SORT_MENU_POPULARITY", kVar.f5579i);
        bundle.putSerializable("SEARCH_BOOKMARK_RANGE", kVar.f5585o);
        bundle.putSerializable("SEARCH_DURATION", kVar.f5586p);
    }

    @Subscribe
    public void onEvent(SearchHistoryEvent searchHistoryEvent) {
        SearchResultContract gVar = this.f18666b0;
        String searchQuery = searchHistoryEvent.getSearchQuery();
        SearchResultPresenter kVar = (SearchResultPresenter) gVar;
        Objects.requireNonNull(kVar);
        MutabilityOwnership.m3745m(searchQuery, "searchQuery");
        kVar.f5573c.m6526d(ABTestingEvent.C3332d.f15550a);
        kVar.f5573c.m6526d(ABTestingEvent.C3329a.f15547a);
        kVar.m9714l(kVar.f5582l, searchQuery);
    }

    @Subscribe
    public void onEvent(ShowRequiredPremiumDialogEvent showRequiredPremiumDialogEvent) {
        this.f18757A.m6528b(7, showRequiredPremiumDialogEvent.getPreviewClickAction());
        AlertDialog.C0305a aVar = new AlertDialog.C0305a(this);
        aVar.m12006h(R.string.premium);
        aVar.m12012b(R.string.search_popular_dialog_description);
        aVar.m12008f(R.string.premium_register, new DialogInterface$OnClickListenerC0191y5(this, showRequiredPremiumDialogEvent, 1));
        aVar.m12011c(R.string.common_cancel, new DialogInterface.OnClickListener(showRequiredPremiumDialogEvent) { // from class: ae.s8

            /* renamed from: b */
            public final /* synthetic */ ShowRequiredPremiumDialogEvent f584b;

            {
                this.f584b = r2;
            }

            @Override // android.content.DialogInterface.OnClickListener
            public final void onClick(DialogInterface dialogInterface, int i) {
                SearchResultActivity searchResultActivity = SearchResultActivity.this;
                ShowRequiredPremiumDialogEvent showRequiredPremiumDialogEvent2 = this.f584b;
                int i2 = SearchResultActivity.f18665h0;
                searchResultActivity.f18757A.m6528b(7, showRequiredPremiumDialogEvent2.getCancelAction());
            }
        });
        aVar.f1085a.f1064n = new DialogInterface.OnCancelListener(showRequiredPremiumDialogEvent) { // from class: ae.q8

            /* renamed from: b */
            public final /* synthetic */ ShowRequiredPremiumDialogEvent f549b;

            {
                this.f549b = r2;
            }

            @Override // android.content.DialogInterface.OnCancelListener
            public final void onCancel(DialogInterface dialogInterface) {
                SearchResultActivity searchResultActivity = SearchResultActivity.this;
                ShowRequiredPremiumDialogEvent showRequiredPremiumDialogEvent2 = this.f549b;
                int i = SearchResultActivity.f18665h0;
                searchResultActivity.f18757A.m6528b(7, showRequiredPremiumDialogEvent2.getCancelAction());
            }
        };
        aVar.m12005i();
    }
}
